package LeetCode.Arrays;

import java.util.Arrays;

/**
 * @author : LdLtd
 * @Date : 2023/7/27
 * @Description:2500. 删除每行中的最大值
 */
public class delete_greatest_value_in_each_row {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int [][] ar={{1,2,4},{3,3,1}};
//        System.out.println(ar.length);
//        System.out.println(ar[0].length);
        System.out.println(solution.deleteGreatestValue(ar));
    }
    static class Solution {
        public int deleteGreatestValue(int[][] grid) {
            int res=0,t=0;
            //对每一行排序
            for (int i = 0; i < grid.length; i++) {
                Arrays.sort(grid[i]);
            }
            for (int i = grid[0].length-1; i >=0; i--) {
                for (int j = 0; j <grid.length; j++) {
                    t=Math.max(t,grid[j][i]);
                }
                res+=t;
                t=0;
            }
            return res;
        }
    }
}
